﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EAppointment.Models
{
    public class UserLoginDetector
    {
        public long UserID
        {
            get;
            private set;
        }
        public bool Detect(ControllerContext controllerContext)
        {
            NameValueCollection HttpParams = System.Web.HttpContext.Current.Request.Params;
            long ID;
            long.TryParse(HttpParams["id"], out ID);
            try
            {
                if (controllerContext.HttpContext.Session["UserInfo"] == null)
                {
                    return false; //Errors.ReturnError(ErrorTypes.NOT_LOGIN);
                }
                else if (((BaseUserInfo)controllerContext.HttpContext.Session["UserInfo"]).ID != ID)
                {
                    return false; //Errors.ReturnError(ErrorTypes.NOT_LOGIN);
                }
            }
            catch
            {
                return false; //Errors.ReturnError(ErrorTypes.NOT_LOGIN);
            }
            return true;
        }
    }
}